package com.abe.libquick.utils;

import android.content.Context;
import android.content.pm.PackageManager;

import com.abe.libcore.base.permission.PermissionUtils;

public class PermissionHelper {
    /**
     * 单权限，手动检查
     *
     * @param context    上下文
     * @param listener   回调
     * @param permission 权限
     */
    public static void single(Context context, final PermissionUtils.PermissionCallback listener, String permission) {
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
            int hasPermission = context.checkPermission(permission, android.os.Process.myPid(), android.os.Process.myUid());
            if (hasPermission != PackageManager.PERMISSION_GRANTED) {
                PermissionUtils.INSTANCE.request(context, listener, permission);
            } else {
                if (listener != null) {
                    listener.onSuccess();
                }
            }
        } else {
            if (listener != null) {
                listener.onSuccess();
            }
        }
    }
}
